<template>
    <view class="container" :style="themeColor">
        <view class="record-top">
            <view class="record-top-top"
                >应付金额<text class="space"
                    >¥<text class="num-text">{{ PriceSum }}</text></text
                ></view
            >
            <view class="record-top-bot">
                <view>
                    <text>待确认金额</text>
                    <view>¥{{ WaitCheckPrice }}</view>
                </view>
                <view style="padding-left: 40rpx">
                    <text>未付金额</text>
                    <view>¥{{ ArrearsPrice }}</view>
                </view>
            </view>
        </view>
        <view class="title">付款记录</view>
        <view class="main">
            <mescroll-uni
                v-if="loadOk"
                ref="mescrollRef"
                @init="mescrollInit"
                :height="height"
                :down="downOption"
                @down="downRefresh"
                :up="upOption"
                @up="getData">
                <view>
                    <view class="list" v-for="item in datas">
                        <view class="list-top">
                            <view>
                                <view class="line"><text></text>{{ item.PayWayName }}</view>
                                <view class="price">¥{{ item.PriceSum }}</view>
                            </view>
                            <view>
                                <view class="time">{{ item.AddTime }}</view>
                                <view class="state">{{ item.StateName }}</view>
                            </view>
                        </view>
                        <view class="list-data">
                            <view><text>交易类型</text><text>付款</text></view>
                            <view v-if="item.BankInfo"
                                ><text>开户银行</text
                                ><text>{{ item.BankInfo.BankTypeName }}{{ item.BankInfo.Branch }}</text></view
                            >
                            <view v-if="item.BankInfo"
                                ><text>账户名称</text><text>{{ item.BankInfo.AccountName }}</text></view
                            >
                            <view v-if="item.BankInfo"
                                ><text>银行账号</text><text>{{ item.BankInfo.Number }}</text></view
                            >
                            <view
                                ><text>流水号</text><text>{{ item.OutTradeNo }}</text></view
                            >
                            <view v-if="item.PayWay == 0"
                                ><text>备注信息</text
                                ><text>{{ item.TransactionId ? item.TransactionId : "无" }}</text></view
                            >
                        </view>
                    </view>
                </view>
            </mescroll-uni>
        </view>
        <view class="footer" v-if="ArrearsPrice > 0">
            <button class="btn btn-main" @click="goUrl('/pages_shop/packet/order/waitPayList?orderId=' + orderId)">
                立即付款
            </button>
        </view>
    </view>
</template>

<script>
import { GetPayListByOrderId } from "@/service/api/order.js"
import { sortBykey } from "@/uni-sub-base/utils/utils.js"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
export default {
    components: {},
    data() {
        return {
            orderId: "",
            loadOk: false,
            height: "", //list所需高度
            param: {},
            datas: [],
            downOption: {
                use: true,
            },
            PriceSum: "",
            ArrearsPrice: "",
            WaitCheckPrice: "",
        }
    },
    onLoad(e) {
        this.orderId = e.orderId
        this.PriceSum = e.PriceSum
        this.ArrearsPrice = e.ArrearsPrice
        this.WaitCheckPrice = e.WaitCheckPrice
    },
    mounted() {
        this.getListHeight()
    },
    methods: {
        getListHeight(element) {
            //获取商品高度
            getElementHeight(this, ".main", (e) => {
                if (this.ArrearsPrice > 0) {
                    this.height = e - 60 + "px"
                } else {
                    this.height = e + "px"
                }
                this.loadOk = true
                this.$nextTick(() => {
                    //#ifndef MP
                    this.downRefresh()
                    //#endif
                })
            })
        },
        //获取列表数据
        getData(page) {
            let param = this.param
            param.pageSize = page.size
            param.pageIndex = page.num
            param.orderId = this.orderId
            GetPayListByOrderId(param).then((res) => {
                if (res.State == 1 && res.Data) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    res.Data.forEach((e, i) => {
                        if (e.BankInfo) {
                            e.BankInfo = JSON.parse(e.BankInfo)
                        }
                    })
                    this.datas = this.datas.concat(res.Data)
                } else {
                    this.mescroll.endBySize(0, 0)
                }
            })
        },
        downRefresh() {
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        goUrl(url) {
            this.easyGoTo(url)
        },
    },
}
</script>

<style lang="scss">
.container {
    padding: $app-page-padding $app-page-padding 0 $app-page-padding;
}
.record-top {
    height: 202rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 54rpx 40rpx 48rpx 40rpx;
    background: $app-color-main url(/static/img/bg-top.png) no-repeat;
    background-size: 100% 100%;
    border-radius: 24rpx;
    color: #ffffff;
    text {
        color: #ffffff;
    }
}
.record-top-top {
    font-size: 28rpx;
    .space {
        padding-left: 26rpx;
    }
}
.num-text {
    font-size: 48rpx;
    font-weight: bold;
}
.record-top-bot {
    display: flex;
    text {
        font-size: 24rpx;
        font-weight: normal;
    }
    view {
        font-size: 40rpx;
        font-weight: bold;
        width: 50%;
    }
}
.title {
    font-size: 32rpx;
    padding: 32rpx 0;
}
.list {
    background: #ffffff;
    border-radius: 24rpx;
    margin-bottom: 28rpx;
    .list-top {
        height: 124rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        border-bottom: 1rpx solid #ebebeb;
        .line {
            display: flex;
            align-items: center;
            font-size: 28rpx;
            font-weight: bold;
            color: #333;
            text {
                width: 8rpx;
                height: 28rpx;
                background: #fa6400;
                border-radius: 4rpx;
                margin-right: 16rpx;
            }
        }
        .price {
            font-size: 32rpx;
            font-weight: bold;
        }
        .time {
            color: #333333;
            font-size: 24rpx;
        }
        .state {
            color: #f7b500;
            font-size: 24rpx;
        }
        & > view {
            display: flex;
            justify-content: space-between;
            padding: 2rpx 24rpx;
        }
    }
    .list-data {
        padding: 24rpx;
        & > view {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6rpx 0;
            text {
                color: $color-gray-2;
            }
        }
    }
}
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 120rpx;
    display: flex;
    background: #ffffff;
    justify-content: center;
    align-items: center;
    padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/
    padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
    .btn {
        color: $color-white;
        background: $app-color-main;
        width: 690rpx;
        height: 90rpx;
        border-radius: 45rpx;
        font-size: 32rpx;
    }
}
</style>
